package com.crossdomain.common;

import java.util.Map;

import net.sf.json.JSONObject;

public class JsonUtils {

    /**
     * json转成成Object对象
     * 
     * @param json
     * @param clazz
     * @return
     */
    @SuppressWarnings("unchecked")
    public static <T> T json2Obj(String json, Class<T> clazz) {
        JSONObject jsonObject = JSONObject.fromObject(json);
        return (T) JSONObject.toBean(jsonObject, clazz);
    }

    /**
     * 
     * @param json
     * @param clazz object类名
     * @param classMap object类的泛型
     * @return
     */
    public static <T> T json2Obj(String json, Class<T> clazz, Map<String, Class<?>> classMap) {
        JSONObject jsonObject = JSONObject.fromObject(json);
        return (T) JSONObject.toBean(jsonObject, clazz, classMap);
    }
}
